<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="com.neusoft.news.bean.News,com.neusoft.news.bean.Column,com.neusoft.news.bean.User"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>新闻页面</title>
<style type="text/css">
.div_news_list{
	color:#3c3c3c;
	background-color: #CCC;
	width: 80%;
	padding-bottom: 10px;
	margin: auto;
	display: flex;
	flex-direction: column;
}
.div_news{
	background-color: white;
	height: 200px;
	width: 98%;
	margin: 10px auto 0px auto;
	display: flex;
}
.div_news_img{
	width: 260px;
	height: 100%;
}
.div_news_img img{
	width: 90%;
	height: 90%;
	margin: 10px;
}
.div_news_msg{
	width: 500px;
	height: 100%;
	flex-grow:1;
}
a{
	color: #3c3c3c;
	text-decoration:none;
}
a:hover{
	color: orange;
}
.div_column_list{
	background-color: #DCDCDC;
	margin: 10px auto;
	width: 80%;
	display: flex;
	justify-content: space-around;
}
.div_column{
	background-color: white;
	margin: 0 10px;
	padding: 10px 30px;
	max-width:100px; 
}

</style>
</head>
<body>
<%	java.util.List<News> newslist = (java.util.List)request.getAttribute("newslist"); %>
<%	java.util.List<Column> columnlist = (java.util.List)request.getAttribute("columnlist"); %>
	<p>
		欢迎你！
		<c:if test="${user.userLevel=='1' }">
			用户：${user.userName }
		</c:if>
		<c:if test="${user.userLevel=='2' }">
			编辑：${user.userName }
			<a href="http://localhost:8080/newsweb/GoToAddNewsPageServlet"><button>投稿</button></a>
		</c:if>
		<c:if test="${user.userLevel=='3' }">
			管理员：${user.userName }
		</c:if>
	</p>
	<div class="div_column_list">
		<a href="http://localhost:8080/newsweb/ShowNewsListServlet">
			<div class="div_column">
				全部
			</div>
		</a>
	<% 
	if(columnlist!=null){ 
		for(Column col:columnlist){
	%>
		<a href="http://localhost:8080/newsweb/ShowNewsByColumnServlet?column_id=<%=col.getColumn_id() %>">
			<div class="div_column">
				<%=col.getColumn_name() %>
			</div>
		</a>
	<% 	} 
	}
	%>
	</div>
<% 	if(newslist!=null){ %>
	<div class="div_news_list">
		<%
		for(News news:newslist){
			//只显示审核通过的新闻和紧急新闻
			if(news.getNews_state().equals("1") || news.getNews_important().equals("1")){
		%>
		<div class="div_news">
			<div class="div_news_img">
			<% if(news.getNews_photo()!= null && !news.getNews_photo().equals("") ){ %>
				<img src="${pageContext.request.contextPath}/img/<%=news.getNews_photo() %>">
			<% } %>
			</div>
			<div class="div_news_msg">
				<a class="a_news_title" href="http://localhost:8080/newsweb/ShowNewsServlet?news_id=<%=news.getNews_id() %>"><h2><%=news.getNews_title() %></h2></a>
				<p class="p_news_author"><a href="#"><%=news.getNews_author() %></a> | <%=news.getNews_date() %></p>
				<p class="p_news_zhaiyao">
					<%=news.getNews_intro() %>
				</p>
			</div>
		</div>
		<%	
			} 
		}
		%>
	</div>
<%} %>
</body>
</html>